package cn.com.doone.common.uc.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.doone.common.uc.utils.MessageUtils;
import cn.com.doone.common.uc.utils.StringUtils;
import cn.com.doone.common.uc.web.BaseController;
import cn.com.doone.common.uc.web.service.SystemService;

@Controller
@RequestMapping(value="/sync")
public class SystemController extends BaseController{

	private final static Logger logger = LoggerFactory.getLogger(SystemController.class);
	
	@Autowired
	private SystemService systemService;
	
	/**
	 * 查询分页列表
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/queryDictPageList", method = RequestMethod.POST)
	public @ResponseBody Map<String,Object> queryDictPageList(HttpServletRequest request) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		Map<String,Object> paramsMap = getParams(request);
		logger.info("参数:"+paramsMap);
		if(StringUtils.isNull(paramsMap.get("page")) || StringUtils.isNull(paramsMap.get("limit"))) {
			resultMap.put("success", false);
			resultMap.put("message", MessageUtils.PARAMS_NULL);
			return resultMap;
		}
		resultMap = systemService.querySysCodePageList(paramsMap);
		return resultMap;
	}
	
	/**
	 * 添加字典
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/mergeDict", method = RequestMethod.POST)
	public @ResponseBody Map<String,Object> mergeDict(HttpServletRequest request) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		Map<String,Object> paramsMap = getParams(request);
		logger.info("参数:"+paramsMap);
		if(StringUtils.isNull(paramsMap.get("typeName")) || StringUtils.isNull(paramsMap.get("value"))) {
			resultMap.put("success", false);
			resultMap.put("message", MessageUtils.PARAMS_NULL);
			return resultMap;
		}
		resultMap = systemService.mergeDict(paramsMap);
		return resultMap;
	}
	
	/**
	 * 修改字典状态
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/changeDictStatus",method = RequestMethod.POST)
	public @ResponseBody Map<String,Object> changeDictStatus(HttpServletRequest request) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		Map<String,Object> paramsMap = getParams(request);
		logger.info("参数:"+paramsMap);
		if(StringUtils.isNull(paramsMap.get("id")) || StringUtils.isNull(paramsMap.get("status"))) {
			resultMap.put("success", false);
			resultMap.put("message", MessageUtils.PARAMS_NULL);
			return resultMap;
		}
		resultMap = systemService.changeDictStatus(paramsMap);
		return resultMap;
	}
}
